﻿@model NK.Mvc3.Models.StoreInput

@{
    ViewBag.Title = "Details";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    function changeBarCode(txt, hiddenProductId, posid) {

        var barCodeValue = $(txt).val();
        //alert(barCodeValue);
        if (barCodeValue != null || barCodeValue != '') {
            $.post('/ProductInfo/GetDetails', { "barcode": barCodeValue },
                function (data) {
                    //alert('post');
                    if (data != null && data.ID > 0) {
                        $(txt).parents('.gridrow').find('#' + posid).val(data.POSDescription);
                        $(txt).parents('.gridrow').find('#' + hiddenProductId).val(data.ID);
                    }
                    else {
                        //alert('error');
                        $(txt).parents('.gridrow').find('#' + posid).val(null);
                        $(txt).parents('.gridrow').find('#' + hiddenProductId).val(null);
                        alert('Wrong BarCode');
                    }
                }
            );

//                $.ajax({
//                    url: '/ProductInfo/GetDetails',
//                    data: { "barcode": barCodeValue },
//                    type: "GET",
//                    dataType: 'json',
//                    error: function (jqXHR, textStatus, errorThrown) { alert('error:' + errorThrown + ", xhr: " + jqXHR); },
//                    success: function (data) { alert(data); }
//                });
        }
    }

    function clearData() {
        $('#ajaxcreateform').find('input[type=text]').val(null);
        $('#ajaxcreateform').find('input[id="hdProductInfoID"]').val(null);
    }

    function loadedUpdate() {
        alert('loadedUpdate');
    }
    function completeUpdated(data) {
        alert(data);
    }
    function loadedUpdateForm() {
        //$.validator.unobtrusive.parse('form');
    }
    $(function () {
        //$.validator.unobtrusive.parse('form');
       // alert('fafd');
    });
    
</script>
<h2>Details</h2>

<fieldset>
    <legend>StoreInput</legend>

    <div class="display-label">DateInput</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DateInput)
    </div>

    <div class="display-label">StaffName</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.StaffName)
    </div>

    <div class="grid">
        <div class="gridheader">
            <div class="gridrow">
                <div class="gridcell">Barcode</div>
                <div class="gridcell">POS Description</div>
                <div class="gridcell">Quantity</div>
                <div class="gridcell">ExpireDate</div>
                <div class="gridcell">FreeQuantity</div>
                <div class="gridcell">CostInput</div>
                <div class="gridcell">TotalCost</div>
                <div class="gridcell action"></div>
            </div>
        </div>
        <div class="gridinsert">
            <div class="gridrow" id="gridinsert">
               @* @Ajax.ActionLink("Create", "AjaxCreate", "StoreInputDetail", new { storeInputId = Model.ID }, new AjaxOptions
                                                                                        {
                                                                                            UpdateTargetId = "gridinsert",
                                                                                            HttpMethod = "GET",
                                                                                            InsertionMode = InsertionMode.Replace,
                                                                                            OnSuccess = "loadedUpdate"
                                                                                        })*@
                @{
                    Html.RenderAction("AjaxCreate", "StoreInputDetail", new {storeInputId = Model.ID});
                }

            </div>
        </div>
        <div class="gridbody" id="gridbody">
            @foreach (var item in Model.StoreInputDetails)
            {
                @:<div class="gridrow" id="gridrow-@item.ID">
                    Html.RenderAction("DetailItem", "StoreInputDetail", new { id = @item.ID });
                @:</div>
            }
        </div>
    </div>
    

</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
    @Html.ActionLink("Back to List", "Index")
</p>
